package com.export.controller;

import com.export.entity.ReportParam;
import com.export.service.IReportService;
import com.rlyy.aibase.utils.base.Box;
import common.util.BoxUtil;
import common.util.validator.ParameterConversionCheck;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;

/**
 * 客户报表
 *
 * @author yuanqinglong
 * @since 2021/7/21 17:58
 */
@RestController
public class CustomerReportController {


    /**
     * 客户报告服务
     */
    @Autowired
    private IReportService<ReportParam> customerReportServiceImpl;



    /**
     * 导出客户报表
     *
     * @param param 参数
     * @return {@link Box}
     */
    @RequestMapping(value = "rsj_report_customer_export")
    public Box exportTable(Box param) {
        ReportParam reportParam = ParameterConversionCheck.parameterConversionCheckFastFail(param, ReportParam.class, Default.class);
        reportParam.processingOperator(param);
        customerReportServiceImpl.exportReportTable(reportParam);
        return BoxUtil.successBox(param).setMsg("文件正在生成中");
    }


    /**
     * 导出客户详情报表
     *
     * @param param 参数
     * @return {@link Box}
     */
    @RequestMapping(value = "rsj_report_customer_detail_export")
    public Box exportDetailTable(Box param) {
        ReportParam reportParam = ParameterConversionCheck.parameterConversionCheckFastFail(param, ReportParam.class, ReportParam.CustId.class, Default.class);
        reportParam.processingOperator(param);
        customerReportServiceImpl.exportDetailTable(reportParam);
        return BoxUtil.successBox(param).setMsg("文件正在生成中");
    }


    /**
     * 下载日志
     *
     * @param param 参数
     * @return {@link Box}
     */
    @RequestMapping(value = "rsj_report_customer_download_log")
    public Box downloadLog(Box param) {
        ReportParam reportParam = ParameterConversionCheck.parameterConversionCheckFastFail(param,
                ReportParam.class, ReportParam.CustId.class, Default.class);
        reportParam.processingOperator(param);
        customerReportServiceImpl.performExport(reportParam,"下载客户日志",reportParam.getOperatorId());
        return BoxUtil.successBox(param).setMsg("文件正在生成中");
    }


}
